<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>药品入库</title>
    <link rel="stylesheet" href="/resource/common/layui/css/layui.css" media="all"/>
</head>
<style>
    .lable-span {
        color: #ea2020;
        padding-left: 3px
    }

    .layui-form-radio > i {
        font-size: 15px;
    }
</style>
<body>
<div class="layui-form" style="padding: 20px">
    <div class="layui-form-item">
        <label for="productUuid" class="layui-form-label">
            药品编号:
        </label>
        <div class="layui-input-block">
            <div class="layui-input-inline">
                <input type="text" id="productUuid" readonly name="productUuid" lay-verify="required"
                       lay-vertype="tips"
                       placeholder="请选择药品"
                       autocomplete="off"
                       class="layui-input">
            </div>
            <div class="layui-input-inline">
                <button class="layui-btn layui-btn-normal btn-w100 search-product"><i
                        class="layui-icon layui-icon-search"></i></button>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label for="stock" class="layui-form-label">
            入库数目:
        </label>
        <div class="layui-input-block">
            <input type="number" id="stock" name="stock" lay-verify="required" lay-vertype="tips"
                   placeholder="请输入入库数目"
                   autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="supplier" class="layui-form-label">
            供应商:
        </label>
        <div class="layui-input-block">
            <input type="text" id="supplier" name="supplier" lay-verify="required" lay-vertype="tips"
                   placeholder="请输入供应商"
                   autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="costPrice" class="layui-form-label">
            成本单价:
        </label>
        <div class="layui-input-block">
            <input type="number" id="costPrice" name="costPrice" lay-verify="required|price" lay-vertype="tips"
                   placeholder="请输入成本单价"
                   autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="content" class="layui-form-label">
            备注:
        </label>
        <div class="layui-input-block">
            <input type="text" id="content" name="content"
                   placeholder="请输入备注信息"
                   autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" style="margin-top: 10px">
        <div class="layui-input-block">
            <input type="hidden" id="productId" name="productId">
            <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="Submit">
                保存
            </button>
            <button type="" class="layui-btn layui-btn-primary close">
                取消
            </button>
        </div>
    </div>
</div>
<script type="text/javascript" src="/resource/common/layui/layui.js"></script>
<script type="text/javascript" th:inline="javascript">

    layui.use(['table', 'layer', 'upload', 'laydate', 'form'], function () {
        var table = layui.table,
            $ = layui.$,
            layer = layui.layer,
            upload = layui.upload,
            form = layui.form;
        //自定义验证规则
        form.verify({
            price: function (value) {
                if (!new RegExp("(^[1-9]\\d*(\\.\\d{1,2})?$)|(^0(\\.\\d{1,2})?$)").test(value)) {
                    return '请输入正确的价格:整数或者保留两位小数';
                }
            }

        });
        $('.close').on('click', function () {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        })
        //查询药品按钮
        $('.search-product').on('click', function () {
            layer.open({
                content: "/inventory/productListPage.do",
                title: '药品信息',
                area: ['90%', '90%'],
                type: 2,
                shadeClose: true
            });
        })
        form.on('submit(Submit)', function (data) {
            $.ajax({
                url: '/inventory/inventory.do',
                type: 'post',
                data: data.field,
                dataType: 'json',
                async: false,
                success: function (result) {
                    if (result.status) {
                        parent.layer.msg("入库成功!", {time: 1000});
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        parent.layui.table.reload('tableId', {});
                    } else {
                        layer.msg(result.msg);
                    }
                }

            });
        });
    });

</script>
</body>
</html>
